<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>IP锁定管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <script type="text/html" id="toolbarDemo">
            <tip>IP连续登录失败超过5次以上即锁定该IP</tip>
        </script>
        <table class="layui-hide" id="userip" lay-filter="currentTableFilter"></table>
        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete"><i class="layui-icon">&#xe673;</i>解锁</a>
        </script>
    </div>
</div>
<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script src="/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script>
    layui.use(['table'], function () {
        var $ = layui.jquery,
            table = layui.table;

        table.render({
            elem: '#userip',
            url: "/api/user/lock",
            method: "get",
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'id', width: 70, title: 'ID', sort: true},
                {field: 'ip', width: 200, title: 'IP', sort: true},
                {field: 'lock', width: 150, title: '登录失败次数', sort: true},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 20, 40, 60, 80, 100],
            limit: 20,
            page: true,
            skin: 'line'
        });

        //监听表格复选框选择
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'delete') {
                layer.confirm('确定解锁该IP吗?', function (index) {
                    $.ajax({
                        url: "/api/user/lock",
                        data: JSON.stringify(data),
                        contentType: 'application/json;charset=UTF-8',
                        dataType: 'json',
                        type: 'delete',
                        success: function (result) {
                            if (result.code == 200) {
                                layer.alert('该IP已解锁!', {title: '提示', icon: 1})
                                table.reload("userip");
                            } else {
                                layer.alert(result.msg, {title: '提示', icon: 2})
                            }
                        },
                        error: function (e) {
                            layer.alert(JSON.stringify(e), {title: '提示', icon: 2})
                        }
                    })
                });
            }
        });

    });
</script>

</body>
</html>
